/**
 * @file 工单列表配置
 * @author yangjiangming <449654337@qq.com>
 * @date 2019/01/15 16:18:52
 */

layui.define(['NP'], function (exports) {
    var NP = layui.NP;

    /**
     * 模板工具
     * @type {{formatMasterInfo, formatUserInfo, formatReplayState}}
     */
    let templateUtils = window.templateUtils = (function () {
        function maskPhone (phone) {
            return phone ? phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') : '';
        }

        function formatUserInfoFactory (isMask) {
            return function (data) {
                var genderStr;
                switch (data.gender) {
                    case 1:
                        genderStr = '先生';
                        break;
                    case 2:
                        genderStr = '女士';
                        break;
                    default:
                        genderStr = '保密';
                        break;
                }

                // var phone = isMask ? maskPhone(data.userPhone) : data.userPhone;
                var phone = data.userPhone;
                return data.username.slice(0, 1) + '(' + genderStr + ')：' + phone;
            }
        }

        return {
            formatUserInfo: formatUserInfoFactory(true),
            formatUserInfoAll: formatUserInfoFactory(),
            formatUserAddress: function (data) {
                return data.userStreet + ' ' + data.userAddress;
            },
            formatFullAddress: function (data) {
                let address = data.countyName + ' ' + data.userStreet + ' ' + data.userAddress;
                return '<span class="btn-address" data-address="' + address + '">' + address + '</span>';
            },
            formatMasterInfo: function (data) {
                if(data.masterName){
                    return data.masterName + '：' + maskPhone(data.masterPhone);
                }
                return '';
            },
            formatProductInfo: function (data) {
                var productInfo = data.productInfo.split('-')[1] || data.productInfo;
                return productInfo + '-' + data.typeName;
            },
            formatRemark: function (data) {
                return '<div class="btn-remark" data-id="' + data.workId + '" style="height: 100%; width: 100%">' + (data.currentRemark || '') + '</div>';
            },
            formatTrackInfo: function (data) {
                return '<div class="btn-track-info" id="btn-track-info' + data.workId + '" data-id="' + data.workId + '" style="height: 100%; width: 100%"></div>';
            },
            formatReplayState: function (data) {
                return data.isReply ? '已回访' : '未回访'
            },
            resultStatusFormatterFactory: function (keyword) {
                return function (data) {
                    var className;
                    var calssStatus;
                    var text;
                    var htmlStr = '';

                    if (keyword === 'status') {
                        className = 'zmn-work-status-' + data.status;
                        text = data.statusName;
                        calssStatus = 'order-status';
                        if (data.multipleVisitStatusName) {
                            htmlStr += '<span>' +
                                '<span class="layui-badge ' + className + ' '+ calssStatus +'">' + text + '</span>' +
                                '<span class="visit-content">主状态：' + text + '<br>子状态：' + data.multipleVisitStatusName + '</span>' +
                                '</span>';
                        } else {
                            htmlStr += '<span class="layui-badge ' + className + '">' + text + '</span>';
                        }

                        return htmlStr;
                    } else if (keyword === 'result') {
                        className = 'zmn-work-result-' + data.resultStatus;
                        text = data.resultStatusName;
                        htmlStr += '<span class="layui-badge ' + className + '">' + text + '</span>';
                        return htmlStr;
                    }

                    /*htmlStr += '<span class="layui-badge ' + className + '">' + text + '</span>';

                    return htmlStr;*/
                }
            },
            formatMoneyToYuan: function (field) {
                return function (data) {
                    var money =  data[field];
                    if (!money) {
                        money = '0.00';
                    } else {
                        money = NP.round(NP.divide(money, 100), 2);
                        money = money.toFixed(2);
                    }

                    return money;
                }
            },
            formatPayStatusName: function (data) {
                var className = 'zmn-pay-status-' + data.payStatus;

                return '<span class="layui-badge ' + className + '">' + data.payStatusName + '</span>';
            },
            formatCityInfo: function (data) {
                return `<span class="btn-company" data-company="${data.companyName}">${data.cityName || ''}</span>`;
            },
            formatWarning: function () {
                /**
                 * 已废弃  投诉等级名称无需前端翻译 接口已返回
                 * @param level
                 * @returns {string}
                 */
                function mapComlaintLevel (level) {
                    var text = '';
                    switch (level) {
                        case 1:
                            text = '一级投诉';
                            break;
                        case 2:
                            text = '二级投诉';
                            break;
                        case 3:
                            text = '三级投诉';
                            break;
                        case 4:
                            text = '四级投诉';
                            break;
                    }

                    // return `<span class="layui-badge zmn-complaint-level-${level}">${text}</span>`;
                    return text;
                }

                return function (data) {
                    var warningBadgeFactory = function (warning, type, text, bgColor) {
                        if (!warning) {
                            return  '';
                        }

                        var classArr = [
                            'layui-badge',
                            'work-warning',
                            `work-warning-${type}`,
                        ].filter(function (item) {
                            return item;
                        });

                        let css = '';
                        if(bgColor){
                            css = 'background: '+bgColor+';';
                        }
                        return (
                            `<span class="${ classArr.join(' ')}" style="${css}">
                                <span class="work-warning-text">
                                    ${ text }
                                </span>
                            </span>`
                        );
                    };
                    var tagBadgeFactory = function (tagList, display) {
                        if (!tagList || tagList.length == 0) {
                            return  '';
                        }

                        htmlStr = ``;
                        for (var i = 0, len = tagList.length; i < len; i++) {
                            let tag = tagList[i];
                            // display 1:列表 2：列表提示
                            if(tag.display){
                                let tagDisplay = ','+tag.display+',';
                                if (tagDisplay.indexOf(','+display+',') < 0) {
                                    continue;
                                }
                            }

                            let name = display == 1 ? tag.tagShortName : tag.tagName;
                            htmlStr = htmlStr +
                                `${ warningBadgeFactory(true, 'tag', name, tag.bgColor) }`;
                        }

                        return htmlStr;
                    };

                    var htmlStr = '';
                    if (data.warningVO) {
                        var warningVO = data.warningVO;
                        var hasWarning = false;

                        Object.keys(warningVO).forEach((key) => {
                            if (warningVO[key]) {
                                hasWarning = true;
                            }
                        });

                        var isDoing = data.resultStatus === 1;
                        if (hasWarning && isDoing) {
                            htmlStr = `<span class="warning-wrapper">
                                <span class="warning">
                                    <!-- 重点渠道 -->
                                    ${ warningBadgeFactory(warningVO.isEmphasisChannel, 'important', '重') }
                                    <!-- 渠道预警 -->
                                    ${ warningBadgeFactory(warningVO.isChannelWarning, 'channel-warning', '渠道',) }
                                    <!-- 提前上门 -->
                                    ${ warningBadgeFactory(warningVO.isVisitEarlyWarning, 'channel-warning', '提前') }
                                    <!-- 一口价 -->
                                    ${ warningBadgeFactory(warningVO.isFinalPrice, 'yikoujia', '一口') }
                                    <!-- VIP -->
                                    ${ warningBadgeFactory(warningVO.isVip, 'vip', 'VIP') }
                                    <!-- 投诉 -->
                                    ${ warningBadgeFactory(warningVO.complainLevel, 'complaint', '投') }
                                    <!-- 异常 -->
                                    ${ warningBadgeFactory(warningVO.hasAbnormal, 'abnormal', '异') }
                                    <!-- 预警 -->
                                    ${ warningBadgeFactory(warningVO.hasWarning, 'warning', '预警') }
                                    <!-- 超时 -->
                                    ${ warningBadgeFactory(warningVO.hasTimeout, 'timeout', '超时') }
                                    <!-- 计价器 -->
                                    ${ warningBadgeFactory(warningVO.isQuotation, 'quotation', '计') }
                                    <!-- 提前付 -->
                                    ${ warningBadgeFactory(warningVO.isAdvancePay, 'quotation', '计') }
                                    <!-- 计价器3.0 -->
                                    ${ warningBadgeFactory(warningVO.isQuotationThree, 'quotation', '计3.0') }
                                    <!-- 挂起 -->
                                    ${ warningBadgeFactory(warningVO.isSuspend, 'suspend', '挂') }
                                    <!-- 待审核 -->
                                    ${ warningBadgeFactory(warningVO.isServiceReview, 'review', '审核') }
                                    <!-- 返修派 -->
                                    ${ warningBadgeFactory(warningVO.isReworkDemand, 'rework-demand', '返') }
                                    <!-- 增值工单 -->
                                    ${ warningBadgeFactory(warningVO.isVas, 'vas', '增') }
                                    <!-- 高价值订单 -->
                                    ${ warningBadgeFactory(warningVO.isHighValueUser, 'high-value-user', '高') }
                                    <!-- 测试 -->
                                    ${ warningBadgeFactory(warningVO.isTest, 'test', '测') }
                                    <!-- tagList -->
                                    ${ tagBadgeFactory(warningVO.tagList, 1) }
                                    <!--审核-->
                                    ${ warningBadgeFactory(warningVO.isRefundWaitReview, 'refund-review', '审') }
                                    <!--待退款-->
                                    ${ warningBadgeFactory(warningVO.isRemit, 'refund-remit', '待退款') }
                                </span>

                                <span class="warning-content">
                                    <!-- 重点渠道 -->
                                    ${ warningBadgeFactory(warningVO.isEmphasisChannel, 'important', '重') }
                                    <!-- VIP -->
                                    ${ warningBadgeFactory(warningVO.isVip, 'vip', 'VVIP') }
                                    <!-- 渠道预警 -->
                                    ${ warningBadgeFactory(warningVO.isChannelWarning, 'channel-warning', '渠道预警') }
                                    <!-- 提前上门 -->
                                    ${ warningBadgeFactory(warningVO.isVisitEarlyWarning, 'channel-warning', '提前上门') }
                                    <!-- 一口价 -->
                                    ${ warningBadgeFactory(warningVO.isFinalPrice, 'yikoujia', '一口价') }
                                    <!-- 投诉 -->
                                    ${ warningVO.complainLevel ? '<span class="layui-badge work-warning zmn-complaint-level-' +  warningVO.complainLevel + '">' + warningVO.complainLevelName + '</span>' : '' }
                                    <!-- 异常 -->
                                    ${ warningBadgeFactory(warningVO.hasAbnormal, 'abnormal', '服务异常') }
                                    <!-- 预警 -->
                                    ${ warningBadgeFactory(warningVO.hasWarning, 'warning', '预警') }
                                    <!-- 超时 -->
                                    ${ warningBadgeFactory(warningVO.hasTimeout, 'timeout', '超时') }
                                    <!-- 计价器 -->
                                    ${ warningBadgeFactory(warningVO.isQuotation, 'quotation', '计价器') }
                                    <!-- 提前付 -->
                                    ${ warningBadgeFactory(warningVO.isAdvancePay, 'quotation', '提前付') }
                                    <!-- 计价器3.0 -->
                                    ${ warningBadgeFactory(warningVO.isQuotationThree, 'quotation', '计价器3.0') }
                                    <!-- 挂起 -->
                                    ${ warningBadgeFactory(warningVO.isSuspend, 'suspend', '挂起') }
                                    <!-- 待审核 -->
                                    ${ warningBadgeFactory(warningVO.isServiceReview, 'review', '审核') }
                                    <!-- 返修派 -->
                                    ${ warningBadgeFactory(warningVO.isReworkDemand, 'rework-demand', '返修派') }
                                    <!-- 测试 -->
                                    ${ warningBadgeFactory(warningVO.isTest, 'test', '测') }
                                    <!-- tagList -->
                                    ${ tagBadgeFactory(warningVO.tagList, 2) }
                                    <!--审核-->
                                    ${ warningBadgeFactory(warningVO.isRefundWaitReview, 'refund-review', '审') }
                                    <!--待退款-->
                                    ${ warningBadgeFactory(warningVO.isRemit, 'refund-remit', '待退款') }
                                </span>
                            </span>`;
                        }
                    }

                    return htmlStr;
                }
            },
            formatCommentScore: function (data) {
                return data.commentScore + '星';
            },
            formatOrderPurposeSaleStatus: function (data) {
                return data.saleStatus === 2 ? '是' : '否';
            }
        }
    })();

    var colsContainer = [
        { field: 'operate', title: '操作', align: 'center', width: 65, fixed: 'right', toolbar: '#btn-operator' },
        { field: 'warningVO', title: '警示', align: 'center', width: 86, templet: templateUtils.formatWarning() },
        { field: 'earlyWarning', title: '预警', align: 'center' },

        { field: 'currentRemark', title: '备注跟单', templet: templateUtils.formatRemark },
        { field: 'username', title: '用户信息', templet: templateUtils.formatUserInfo },
        { field: 'userPhone', title: '用户信息', templet: templateUtils.formatUserInfoAll },

        { field: 'countyName', title: '地址', minWidth: 225, sort: true, templet: templateUtils.formatFullAddress },
        { field: 'provinceCityName', title: '省市', minWidth: 225,  templet: '<span>{{d.provinceName}} {{d.cityName}}</span>>' },

        { field: 'productInfo', title: '服务信息', minWidth: 225, sort: true, templet: templateUtils.formatProductInfo },
        { field: 'faultContent', title: '故障信息' },
        { field: 'masterName', title: '工程师', sort: true, templet: templateUtils.formatMasterInfo },
        { field: 'status', title: '状态', align: 'center', sort: true, templet: templateUtils.resultStatusFormatterFactory('status') },
        { field: 'resultStatus', title: '结果', align: 'center', sort: true, templet: templateUtils.resultStatusFormatterFactory('result') },
        { field: 'payStatusName', title: '支付状态', align: 'center', sort: true, templet: templateUtils.formatPayStatusName },
        { field: 'isReply', title: '回访', align: 'center', width: 65, templet: templateUtils.formatReplayState },
        { field: 'channelName', title: '下单渠道', sort: true },

        { field: 'cityName', title: '城市', templet: templateUtils.formatCityInfo },
        { field: 'isMember', title: '延保订单' },
        { field: 'reviewStatusName', title: '审核状态' },
        { field: 'equtityTypeName', title: '会员权益' },

        { field: 'receiveTime', title: '下单时间', width: 100, align: 'center', sort: true },
        { field: 'checkoutTime', title: '收单时间' },
        { field: 'accountTime', title: '算账时间' },
        { field: 'dutyTime', title: '预约时间', width: 100, align: 'center', sort: true },
        { field: 'commentTime', title: '评价时间', width: 150, align: 'center', sort: true },

        { field: 'originalAmount', title: '订单金额', templet: templateUtils.formatMoneyToYuan('originalAmount') },
        { field: 'discountAmount', title: '优惠', templet: templateUtils.formatMoneyToYuan('discountAmount') },
        { field: 'totalAmount', title: '订单收入', templet: templateUtils.formatMoneyToYuan('totalAmount') },
        { field: 'invoiceAmount', title: '发票金额', templet: templateUtils.formatMoneyToYuan('invoiceAmount') },
        { field: 'partAmount', title: '配件销售总额', templet: templateUtils.formatMoneyToYuan('partAmount') },
        { field: 'subsidyAmount', title: '绩效基数补贴', templet: templateUtils.formatMoneyToYuan('subsidyAmount') },
        { field: 'billAmount', title: '工程师绩效基数', templet: templateUtils.formatMoneyToYuan('billAmount') },
        { field: 'masterRewardsAmount', title: '提成总额', templet: templateUtils.formatMoneyToYuan('masterRewardsAmount') },
        { field: 'settleAmount', title: '到账结算', templet: templateUtils.formatMoneyToYuan('settleAmount') },
        { field: 'channelAmount', title: '渠道佣金', templet: templateUtils.formatMoneyToYuan('channelAmount') },
        { field: 'partReimburseAmount', title: '配件报销', templet: templateUtils.formatMoneyToYuan('partReimburseAmount') },

        { field: 'cityName', title: '城市', align: 'center', sort: true },
        { field: 'commentScore', title: '评星', align: 'center', width: 65, templet: templateUtils.formatCommentScore },
        { field: 'typeName', title: '评价方式', align: 'center' },
        { field: 'commentContent', title: '评价内容' },

        { field: 'purposeProductInfo', title: '服务信息',align: 'center', templet: (d) => d.productInfo },
        { field: 'saleStatus', title: '是否售卖', align: 'center', templet: templateUtils.formatOrderPurposeSaleStatus },
        { field: 'servCategName', title: '服务分类', align: 'center' },
        { field: 'creater', title: '录入人', align: 'center' }
    ];

    function tableColsMaper (colsContainer) {
        return function (fields) {
            var cols = [];
            fields.forEach((field) => {
                var col = colsContainer.find((col) => col.field === field);
                if (col) {
                    cols.push(col);
                }
            });

            return cols;
        }
    }

    var tableColsFactory  = tableColsMaper(colsContainer);

    /**
     * 普通工单查询工单列表字段
     * @type {string[]}
     */
    var fieldsOfNormalTable = [
        'warningVO', 'receiveTime', 'dutyTime',
        'currentRemark', 'username', 'countyName', 'productInfo', 'faultContent',
        'masterName', 'status', 'resultStatus', 'payStatusName', 'isReply',
        'channelName',
        'operate'
    ];

    /**
     * 子公司财务工单查询工单列表字段
     * @type {string[]}
     */
    var fieldsOfBranchFinanceTable = [
        'checkoutTime', 'accountTime', 'masterName', 'productInfo',
        'originalAmount', 'discountAmount', 'totalAmount', 'partAmount',
        'subsidyAmount', 'billAmount', 'bonusAmount', 'masterRewardsAmount',
        'status', 'resultStatus', 'payStatusName',
        'operate'
    ];

    /**
     * 总公司财务工单查询工单列表字段
     * @type {string[]}
     */
    var fieldsOfHqFinanceTable = [
        'productInfo', 'originalAmount', 'discountAmount',
        'totalAmount', 'settleAmount', 'channelAmount', 'partAmount',
        'partReimburseAmount', 'subsidyAmount', 'billAmount',
        'bonusAmount', 'invoiceAmount', 'masterRewardsAmount',
        'status', 'resultStatus', 'channelName',
        'operate'
    ];

    /**
     * 话务工单查询工单列表字段
     * @type {string[]}
     */
    var fieldsOfCustomerServiceTable = [
        'warningVO', 'receiveTime', 'dutyTime', 'username', 'countyName',
        'productInfo', 'faultContent', 'masterName',
        'status', 'resultStatus', 'payStatusName',
        'operate'
    ];

    /**
     * 会员工单查询工单列表字段
     * @type {string[]}
     */
    var fieldstOfMemberTable = [
        'warningVO', 'receiveTime', 'dutyTime',
        'currentRemark','username', 'productInfo', 'status', 'resultStatus',
        'masterName', 'cityName', 'equtityTypeName', 'isMember', 'reviewStatusName',
        'operate'
    ];

    /**
     * 品控工单查询工单列表字段
     * @type {string[]}
     */
    var fieldsOfQualityControlTable = [
        'warningVO', 'receiveTime', 'dutyTime', 'currentRemark',
        'countyName', 'productInfo', 'masterName',
        'status', 'resultStatus', 'payStatusName',
        'operate'
    ];

    /**
     * 工单评价查询列表字段
     * @type {string[]}
     */
    var fieldsOfWorkCommentTable = [
        'commentTime', 'cityName',
        'commentScore', 'typeName', 'commentContent',
        'masterName', 'channelName', 'isReply',
        'operate'
    ];

    /**
     * 言而有信工单评价查询列表字段
     * @type {string[]}
     */
    var fieldsOfYsWorkCommentTable = [
        'commentTime', 'cityName',
        'commentScore', 'typeName', 'commentContent',
        'masterName', 'channelName',
        'operate'
    ];
    /**
     * 一步维修工单评价查询列表字段
     * @type {string[]}
     */
    var fieldsOfSaasWorkCommentTable = [
        'commentTime', 'cityName',
        'commentScore', 'typeName', 'commentContent',
        'masterName', 'channelName',
        'operate'
    ];
    /**
     * 一步维修工单评价查询列表字段
     * @type {string[]}
     */
    var fieldsOfCnhbWorkCommentTable = [
        'commentTime', 'cityName',
        'commentScore', 'typeName', 'commentContent',
        'masterName', 'channelName',
        'operate'
    ];

    /**
     * 意向单查询列表字段
     * @type {string[]}
     */
    var fieldsOfOrderPurposeTable = [
        'receiveTime', 'userPhone',
        'countyName', 'purposeProductInfo', 'saleStatus',
        'servCategName', 'creater',
        'operate'
    ];

    /**
     * 言而有信工单查询工单列表字段
     * @type {string[]}
     */
    var fieldsOfYeyxTable = [
        'warningVO', 'receiveTime', 'dutyTime',
        'currentRemark', 'username', 'provinceCityName', 'countyName', 'productInfo', 'faultContent',
        'masterName', 'status', 'resultStatus', 'payStatusName', 'isReply',
        'operate'
    ];

    /**
     * 全部工单列表字段
     * @type {string[]}
     */
    var fieldsOfAllTable = [
        'warningVO', 'receiveTime', 'dutyTime',
        'currentRemark', 'username', 'provinceCityName', 'countyName', 'productInfo',
        'masterName', 'status', 'resultStatus', 'payStatusName', 'isReply','channelName',
        'operate',
    ];

    /**
     * 一步维修工单查询工单列表字段
     * @type {string[]}
     */
    var fieldsOfSaasTable = [
        'warningVO', 'receiveTime', 'dutyTime',
        'currentRemark', 'username', 'provinceCityName', 'countyName', 'productInfo',
        'masterName', 'status', 'resultStatus', 'payStatusName', 'isReply',
        'channelName',
        'operate'
    ];

    /**
     * 川南环保工单查询工单列表字段
     * @type {string[]}
     */
    var fieldsOfCnhbTable = [
        'warningVO', 'receiveTime', 'dutyTime',
        'currentRemark', 'username', 'provinceCityName', 'countyName', 'productInfo',
        'masterName', 'status', 'resultStatus', 'payStatusName', 'channelName', 'operate'
    ];


    // 普通
    var configOfNormalTable = {
        rowURL: '/work/ajax/row.action',
        exportURL: '/work/list/export/async.action',
        exportAsync:true,
        orderObj: {
            orderField: 'receiveTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 510,
        initialSearch: false,
        config: {
            url: '/work/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };
    // 子公司财务
    var configOfBranchFinanceTable = {
        rowURL: '/branchfinance/work/ajax/row.action',
        exportURL: '',
        orderObj: {
            orderField: 'dutyTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 510,
        initialSearch: false,
        config: {
            url: '/branchfinance/work/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };
    // 话务
    var configOfCustomerServiceTable = {
        rowURL: '/customerservice/work/ajax/row.action',
        exportURL: '',
        orderObj: {
            orderField: 'dutyTime',
            defaultOrder: 2,
        },
        defaultParams: {
            tabType: 1
        },
        moduleId : 550,
        initialSearch: false,
        paramsNotEmpty:true,
        config: {
            url: '/customerservice/work/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };
    // 总部财务
    var configOfHqFinanceTable = {
        rowURL: '/hqfinance/work/ajax/row.action',
        exportURL: '',
        orderObj: {
            orderField: 'dutyTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 530,
        initialSearch: false,
        config: {
            url: '/hqfinance/work/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };
    // 会员
    var configOfMemberTable = {
        rowURL: '/member/work/ajax/row.action',
        exportURL: '/member/work/exportexcel',
        exportAsync:false,
        orderObj: {
            // orderField: 'dutyTime',
            orderField: 'receiveTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 520,
        initialSearch: false,
        config: {
            url: '/member/work/ajax/list.action',
            toolbar: '#toolbarTmpl',
            defaultToolbar: ['filter', 'print']
        }
    };
    // 品控
    var configOfQualityControlTable = {
        rowURL: '/qualitycontrol/work/ajax/row.action',
        exportURL: '',
        orderObj: {
            orderField: 'dutyTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 560,
        initialSearch: false,
        config: {
            url: '/qualitycontrol/work/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };

    // 工单评价
    var workCommentTable = {
        rowURL: '',
        exportURL: '/order_comment/exportexcel.action',
        exportAsync:false,
        orderObj: {
            orderField: 'commentTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 570,
        initialSearch: false,
        config: {
            url: '/order_comment/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };

    // 意向单
    var orderPurposeTable = {
        rowURL: '',
        exportURL: '/order/purpose/list/export.action',
        exportAsync:false,
        orderObj: {
            orderField: 'createTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        initialSearch: false,
        config: {
            url: '/order/purpose/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };

    // 言而有信工单评价
    var ysWorkCommentTable = {
        rowURL: '',
        exportURL: '/ys/order_comment/exportexcel.action',
        exportAsync:false,
        orderObj: {
            orderField: 'commentTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 571,
        initialSearch: false,
        config: {
            url: '/ys/order_comment/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };
    // 一步维修工单评价
    var saasWorkCommentTable = {
        rowURL: '',
        exportURL: '/saas/order_comment/exportexcel.action',
        exportAsync:false,
        orderObj: {
            orderField: 'commentTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 573,
        initialSearch: false,
        config: {
            url: '/saas/order_comment/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };
    // 川南环保工单评价
    var cnhbWorkCommentTable = {
        rowURL: '',
        exportURL: '/cnhb/order_comment/exportexcel.action',
        exportAsync:false,
        orderObj: {
            orderField: 'commentTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 575,
        initialSearch: false,
        config: {
            url: '/cnhb/order_comment/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };

    // 言而有信
    var configOfYeyxTable = {
        rowURL: '/ys/work/ajax/row.action',
        exportURL: '/ys/work/list/export/async.action',
        exportAsync:true,
        orderObj: {
            orderField: 'receiveTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 590,
        initialSearch: false,
        config: {
            url: '/ys/work/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };

    // 全部工单
    var configOfAllTable = {
        rowURL: '/all/work/ajax/row.action',
        exportURL: '/all/work/list/export/async.action',
        exportAsync:true,
        orderObj: {
            orderField: 'receiveTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 510,
        paramsNotEmpty: true,
        initialSearch: false,
        config: {
            url: '/all/work/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };

    // 一步维修工单
    var configOfSaasTable = {
        rowURL: '/saas/work/ajax/row.action',
        exportURL: '/saas/work/list/export/async.action',
        exportAsync:true,
        orderObj: {
            orderField: 'receiveTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 572,
        initialSearch: false,
        config: {
            url: '/saas/work/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };

    // 川南环保工单
    var configOfCnhbTable = {
        rowURL: '/cnhb/work/ajax/row.action',
        exportURL: '/cnhb/work/list/export/async.action',
        exportAsync:true,
        orderObj: {
            orderField: 'receiveTime',
            defaultOrder: 2,
        },
        defaultParams: {
            data: []
        },
        moduleId : 574,
        initialSearch: false,
        config: {
            url: '/cnhb/work/ajax/list.action',
            defaultToolbar: ['filter', 'print']
        }
    };

    /**
     * 列表名与字段映射
     */
    var fieldsMap = {
        normal: fieldsOfNormalTable,
        branchFinance: fieldsOfBranchFinanceTable,
        hqFinance: fieldsOfHqFinanceTable,
        customerService: fieldsOfCustomerServiceTable,
        member: fieldstOfMemberTable,
        qualityControl: fieldsOfQualityControlTable,
        workComment: fieldsOfWorkCommentTable,
        orderPurpose: fieldsOfOrderPurposeTable,

        ysWorkComment: fieldsOfYsWorkCommentTable,
        yeyx: fieldsOfYeyxTable,
        all: fieldsOfAllTable,
        saas: fieldsOfSaasTable,
        saasWorkComment: fieldsOfSaasWorkCommentTable,
        cnhb:fieldsOfCnhbTable,
        cnhbWorkComment: fieldsOfCnhbWorkCommentTable
    };

    /**
     * 列表名与数据表配置映射
     */
    var tableConfigMap = {
        normal: configOfNormalTable,
        branchFinance: configOfBranchFinanceTable,
        customerService: configOfCustomerServiceTable,
        member: configOfMemberTable,
        hqFinance: configOfHqFinanceTable,
        qualityControl: configOfQualityControlTable,
        workComment: workCommentTable,
        orderPurpose: orderPurposeTable,

        ysWorkComment: ysWorkCommentTable,
        yeyx: configOfYeyxTable,
        all: configOfAllTable,
        saas:configOfSaasTable,
        saasWorkComment: saasWorkCommentTable,
        cnhb:configOfCnhbTable,
        cnhbWorkComment: cnhbWorkCommentTable
    };

    function createTableConfig (tableName) {
        var baseConfig = tableConfigMap[tableName];

        // if (tableName.toLowerCase().includes('comment')) {
        //     var cols = tableColsFactory(fieldsMap[tableName] || []);
        //     baseConfig.config.cols = [cols];
        // }

        return baseConfig;
    }

    exports('oms_common_table_config', {
        createTableConfig: createTableConfig
    });
});
